package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "菜单相关接口")
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dish) {
        log.info("添加菜品:{}",dish);
        dishService.addDish(dish);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("菜单分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        log.info("菜单分页查询:{}",dishPageQueryDTO);
        return Result.success(dishService.page(dishPageQueryDTO));
    }

    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result deleteDish(@RequestParam List<Long> ids) {
        dishService.deleteDish(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> getDishById(@PathVariable Long id) {
        log.info("id回显:{}",id);
       DishVO dish = dishService.getDishById(id);
       return Result.success(dish);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDish(@RequestBody DishDTO dish) {
        log.info("修改菜品:{}",dish);
        dishService.updateDish(dish);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据id分类查询")
    public Result<List<DishVO>> listDish(Long categoryId) {
        log.info("根据id查询:{}",categoryId);
        return Result.success(dishService.listDish(categoryId));
    }

    @PostMapping("/status/{status}")
    @ApiOperation("菜品状态")
    public Result updateDishStatus(@PathVariable Integer status, Long id) {
        dishService.updateDishStatus(status,id);
        return Result.success();
    }
}
